import config_set from "./baseUrl.js"
var http = function(config) {
	let token = ''
	uni.getStorage({
		key: 'token',
		success: function(res) {
			token = res.data
		}
	});

	console.log(token);
	return new Promise((resolve, reject) => {
		uni.request({
			url: config_set.baseUrl + config.url,
			data: config.data,
			method: config.method,
			header: {
				'token': token
			},
			success: res => {
				if (res.data.code == 401) {
					uni.clearStorage()
					return
				}
				if (res.data.code == 10086) {
					uni.showToast({
						icon: 'none',
						title: res.data.message,
						duration: 2000,
					});
					return
				}
				if (res.data.code == 10088) {
					uni.removeStorageSync('token')
					uni.showModal({
						title: '提醒',
						content: '为了您更好地体验，请先登录',
						success: function(res) {
							if (res.confirm) {
								window.location.href =
									`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9b3253054a85a97a&redirect_uri=${encodeURIComponent('https://fykq.appldkj.com/#/pages/user/user')}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return
				}
				resolve(res.data)
			},
			fail(err) {
				reject(err)
			},
		})
	})
}
export default http